<template>
    <el-main>
        <el-card class="box-card">
            {{msg}}
        </el-card>
    </el-main>
</template>
<script>
import { Loading } from 'element-ui';
import {HttpHandler} from '@/api/Gener.js'
export default {
    data(){
        return{
            msg:'',
            FK_Flow:''
        }

    },
    methods:{
        initData:function(){
            this.FK_Flow = this.$route.params.FK_Flow;
            var fromPage = this.$route.params.FromPage;
            if(fromPage == "Start" || fromPage=="Todolist")
                this.myFlowInit();
            else
               this.myFrmInit(); 
        },
        myFlowInit:function(){
            
            //整页加载
            let loadingInstance = Loading.service({ fullscreen: true });

            //获取数据
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_MyFlow");
            handler.AddJson(this.$route.params);
            var data = handler.DoMethodReturnString("MyFlow_Init");

            // 以服务的方式调用的 Loading 需要异步关闭
            this.$nextTick(() => { 
            loadingInstance.close();
            });

            //处理数据
            if (data.indexOf('err@') == 0) {
                this.msg="<br>" + data;
                return;
            }

            if (data.indexOf('url@') == 0) {

                data = data.replace('url@', ''); //如果返回url，就直接转向.
                data = data.replace('?DoType=HttpHandler', '?');
                data = data.replace('&DoType=HttpHandler', '');
                data = data.replace('&DoMethod=MyFlow_Init', '');
                data = data.replace('&HttpHandlerName=BP.WF.HttpHandler.WF_MyFlow', '');
                data = data.replace('?&', '?');
                //获取跳转的路由
                var routerName = data.substr(data.lastIndexOf("/")+1,data.indexOf('?'));
                routerName = routerName.replace(".html","").replace(".htm","");
                //获取？号后面的参数
                var params = data.substr(data.indexOf('?')+1).split('&');
                var myJson = {};
                for (var i = 0; i < params.length; i++) {
                    var hash = params[i].split('=');
                    myJson[hash[0]] = hash[1];
                }
                 myJson["IsShowBtn"] = 1;
                // vuex 保存数据
                this.$store.commit('setData', myJson)
                //如果返回url，就直接转向.
                this.$router.push({
                    name: routerName,
                    params:myJson
                });
                return;
            }

            this.msg= data;
        },
        myFrmInit:function(){
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_CCForm");
            handler.AddJson(this.$route.params);
            var data = handler.DoMethodReturnString("Frm_Init");
            //处理数据
            if (data.indexOf('err@') == 0) {
                this.msg="<br>" + data;
                return;
            }
            if (data.indexOf('url@') == 0) {
                data = data.replace('url@', ''); //如果返回url，就直接转向.
                data = data.replace("FrmGener.htm","MyFlowGener.htm");
                 //获取跳转的路由
                var routerName = data.substr(data.lastIndexOf("/")+1,data.indexOf('?'));
                routerName = routerName.replace(".html","").replace(".htm","");
                //获取？号后面的参数
                var params = data.substr(data.indexOf('?')+1).split('&');
                var myJson = {};
                for (var i = 0; i < params.length; i++) {
                    var hash = params[i].split('=');
                    myJson[hash[0]] = hash[1];
                }
                myJson["IsShowBtn"] = 0;
                // vuex 保存数据
                this.$store.commit('setData', myJson)
                //如果返回url，就直接转向.
                this.$router.push({
                    name: routerName,
                    params:myJson
                });
                return;
            }
            this.msg= data;
        }
    },
    created(){
        this.initData();
        
    }
}
</script>